--------------------
-- Point class
--------------------
Point = {}
Point.__index = Point

function Point.new(x, y)
    local p = {}
    setmetatable(p, Point)
    
    -- variables
    p.x = x or 0
    p.y = y or 0
    
    return p
end


--------------------
-- Set point
--------------------
function Point:set(x, y)
    self.x = x
    self.y = y
end

--------------------
-- toString
--------------------
function Point:toString()
	return ("Point x:" .. self.x .. " y: " .. self.y)
end


--------------------
-- Line class
--------------------
Line = {}
Line.__index = Line

function Line.new(x1, y1, x2, y2)
    local l = {}
    setmetatable(l, Line)
    
    -- variables
    l.x1 = x1
    l.y1 = y1
    l.x2 = x2
    l.y2 = y2
    
    return l
end

--------------------
-- Length
--------------------
function Line:length()
    return math.sqrt(math.pow(self.x2 - self.x1, 2) + math.pow(self.y2 - self.y1, 2))
end


--------------------
-- Rectangle class
--------------------
Rectangle = {}
Rectangle.__index = Rectangle

function Rectangle.new(x, y, w, h)
    local r = {}
    setmetatable(r, Rectangle)
    
    -- variables
    r.x = x
    r.y = y
    r.width = w
    r.height = h
    
    return r
end

--------------------
-- Gets left
--------------------
function Rectangle:left()
    return self.x
end

--------------------
-- Gets right
--------------------
function Rectangle:right()
    return (self.x + self.width)
end

--------------------
-- Gets top
--------------------
function Rectangle:top()
    return self.y
end

--------------------
-- Gets bottom
--------------------
function Rectangle:bottom()
    return (self.y + self.height)
end

--------------------
-- Gets topLeft
--------------------
function Rectangle:topLeft()
    return self:left(), self:top()
end

--------------------
-- Gets topRight
--------------------
function Rectangle:topRight()
    return self:right(), self:top()
end

--------------------
-- Gets bottomLeft
--------------------
function Rectangle:bottomLeft()
    return self:left(), self:bottom()
end

--------------------
-- Gets bottomRight
--------------------
function Rectangle:bottomRight()
    return self:right(), self:bottom()
end

--------------------
-- set size
--------------------
function Rectangle:setSize(w, h)
    self.width = w
    self.height = h
end

--------------------
-- set position
--------------------
function Rectangle:setPosition(x, y)
    self.x = x
    self.h = h
end

--------------------
-- set rect
--------------------
function Rectangle:set(x, y, w, h)
    self:setPosition(x, y)
    self:setSize(w, h)
end

--------------------
-- center
--------------------
function Rectangle:center()
	local x_middle = self:left() + self.width * 0.5
	local y_middle = self:top() + self.height * 0.5
	
	return x_middle, y_middle
end

--------------------
-- center x
--------------------
function Rectangle:centerX()
	return (self:left() + self.width * 0.5)
end

--------------------
-- center y
--------------------
function Rectangle:centerY()
	return (self:top() + self.height * 0.5)
end

